from django.db import models

from apps.users.models import Users_model
from utils.baseModel import UtilsModel
from apps.business.models import Contract_papers_model
# Create your models here.
# 项目表
class Projects_model(UtilsModel):
    pro_name = models.CharField(max_length=255,null=False,verbose_name='项目名称')
    pro_contract = models.OneToOneField(Contract_papers_model,null=False,on_delete=models.CASCADE,verbose_name='关联约定书')
    pro_number = models.CharField(max_length=128,null=True,verbose_name='文号')
    sign_one = models.ForeignKey(Users_model, related_name='user_one', on_delete=models.CASCADE, verbose_name='签字人一')
    sign_one_opinion = models.ForeignKey('Projects_opinion_model', related_name='userone_opinion',default=None,on_delete=models.CASCADE, verbose_name='签字人一的意见')
    sign_two = models.ForeignKey(Users_model, related_name='user_two', on_delete=models.CASCADE, verbose_name='签字人二')
    sign_two_opinion = models.ForeignKey('Projects_opinion_model', related_name='usertwo_opinion',default=None,on_delete=models.CASCADE, verbose_name='签字人二的意见')
    print_amount = models.PositiveIntegerField(null=False,verbose_name='打印份数')
    status_type = (
        (1, '拟定'),
        (2, '终止'),
        (3, '执行中'),
        (4, '项目完成')
    )
    pro_status = models.IntegerField(choices=status_type, null=False, default=1,
                                   verbose_name='状态状态')
    def __str__(self):
        return self.id

    class Meta:
        verbose_name_plural = '项目表'

# 签字人意见表
class Projects_opinion_model(UtilsModel):
    opinion_name = models.CharField(max_length=64,  null=False, verbose_name='签字人意见')
    def __str__(self):
        return self.id

    class Meta:
        verbose_name_plural = '签字人意见表 '

# 项目人员表
class Projects_users_model(models.Model):
    user_project = models.OneToOneField(Projects_model,null=False,on_delete=models.CASCADE,verbose_name='关联项目') # 这里允许多个项目拥有多个项目成员
    user_user = models.ManyToManyField(Users_model, null=False, verbose_name='关联人员')  # 这里允许多个项目拥有多个项目成员
    ind_type = (
        (0, '需要签署'),
        (1, '无需签署'),
    )
    user_Independence = models.IntegerField(choices=ind_type, null=False, default=1,verbose_name='是否需要前速独立性申明')

    def __str__(self):
        return self.id

    class Meta:
        verbose_name_plural = '项目人员表'